// Product detail page
// ===================

define(['require', 'zepto', 'wxshare', 'utils', 'page/protocol', 'sui', 'smExtend'], 
        function(require, $, wxshare, utils, protocol) {
  return {
    init: function(data) {
      
      $(".swiper-container").swiper({
        autoplay: 3000
      });
      
      var time =  (new Date()).getTime();
      if(time >= 1599732000000) {
        $(".open-select-btn").html("立即购买")
      }
      
      var interval = setInterval(function() {
        var time =  (new Date()).getTime();
        if(time >= 1599732000000) {
          $(".open-select-btn").html("立即购买")
          clearInterval(interval)
        }
      }, 1000)
      
      wxshare.initShare(data.jsConfig, true, {
        name: "人马君乐在美味即食魔芋拌面",
        desc: "人马君 乐在美味即食魔芋拌面（肽+） 轻卡低热量 减脂餐 魔芋面主食品方便即食速食",
        link: "http://weixin.fit-start.co/moyu",
        cover: "https://prod.qiniu.fit-start.edoomath.com/moyu-logo.png"
      })
      
      var url = $(".go-btn").attr("href").split("?")[0];
      
      $(".open-select-btn").on("click", function(e) {
        
        var time =  (new Date()).getTime();
        if(time > 1599732000000) {
          $.popup('.select-pop');
        } else {
          $.toast("18:00准时开放购买！")
        }
        
      })
      
      
      $(".label-area label").on("click", function(e) {
        $(".label-info").html($(this).html());
        
        $(".label-area label").each(function() {
          $(this).removeClass("active")
        })
        $(this).addClass("active")
        url = url.split("?")[0];
        url = url + "?type=" + ($(".label-area label.active").html() === "香辣钵钵鸡味6盒" ? "1" : $(".label-area label.active").html() === "葱油鸡汁味6盒" ? "2" : "3");
        url = url + "&amount=" + $(".value-btn").html();
        $(".go-btn").attr("href", url)
      })
      
      $(".jian-btn").on("click", function(e) {
        var value = parseInt($(".value-btn").html());
        if(value == 1) {
          $(".value-btn").html("1");
        } else {
          $(".value-btn").html(value-1);
        }
        url = url.split("?")[0];
        url = url + "?type=" + ($(".label-area label.active").html() === "香辣钵钵鸡味6盒" ? "1" : $(".label-area label.active").html() === "葱油鸡汁味6盒" ? "2" : "3");
        url = url + "&amount=" + $(".value-btn").html();
        $(".go-btn").attr("href", url)
      })
      
      $(".jia-btn").on("click", function(e) {
        var value = parseInt($(".value-btn").html());
        $(".value-btn").html(value+1);
        url = url.split("?")[0];
        url = url + "?type=" + ($(".label-area label.active").html() === "香辣钵钵鸡味" ? "1" : "2");
        url = url + "&amount=" + $(".value-btn").html();
        $(".go-btn").attr("href", url)
      })
    }
  }
})